﻿Public Class frmPoint
    Dim mysql As New ClsSQLhelper
    Dim strsql As String
    Dim DT_m_files_upload As New DataTable
    Dim On_Load As Boolean = True
#Region "Function"
    Sub View_Point()
        Try
            Dim DT_m_upload As New DataTable

            strsql = "Select * from m_upload where upload_id  = "
            If Me.CboImportOPFile.Items.Count < 1 Then
                strsql = strsql & DT_m_files_upload.Rows(0).Item("ROWID").ToString
            Else
                strsql = strsql & CboImportOPFile.SelectedValue
            End If

            DT_m_upload = mysql.GetMYSQLDataTable(strsql, "m_upload")
            If DT_m_upload.Rows.Count < 1 Then
                MsgBox("ไม่พบข้อมูล", MsgBoxStyle.Exclamation)
                Exit Sub
            End If


            For Each DR_User In DT_m_upload.Select("FILENAME = 'PERSON'")
                LvOPScore.Items(0).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LvOPScore.Items(0).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LvOPScore.Items(0).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'SERVICE'")
                LvOPScore.Items(1).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LvOPScore.Items(1).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LvOPScore.Items(1).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'DIAG'")
                LvOPScore.Items(2).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LvOPScore.Items(2).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LvOPScore.Items(2).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'PROCED'")
                LvOPScore.Items(3).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LvOPScore.Items(3).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LvOPScore.Items(3).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'DRUG'")
                LvOPScore.Items(4).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LvOPScore.Items(4).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LvOPScore.Items(4).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            'OP Add on
            strsql = "Select * from m_upload where upload_id  = "
            If Me.CboImportOPFile.Items.Count < 1 Then
                strsql = strsql & DT_m_files_upload.Rows(0).Item("ROWID").ToString
            Else
                strsql = strsql & CboImportOPFile.SelectedValue
            End If
            strsql = strsql & " and Type = 'B'"

            DT_m_upload = mysql.GetMYSQLDataTable(strsql, "m_upload")
            If DT_m_upload.Rows.Count < 1 Then
                MsgBox("ไม่พบข้อมูล", MsgBoxStyle.Exclamation)
                Exit Sub
            End If
            For Each DR_User In DT_m_upload.Select("FILENAME = 'PROCED'")
                LvOPAddon.Items(0).SubItems.Item(1).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'DRUG'")
                LvOPAddon.Items(1).SubItems.Item(1).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'REFER'")
                LvOPAddon.Items(2).SubItems.Item(1).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Exit For
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Try
            Dim DT_m_upload As New DataTable

            strsql = "Select * from m_upload where upload_id  = "
            If Me.CboImportPPFile.Items.Count < 1 Then
                strsql = strsql & DT_m_files_upload.Rows(0).Item("ROWID").ToString
            Else
                strsql = strsql & CboImportPPFile.SelectedValue
            End If

            DT_m_upload = mysql.GetMYSQLDataTable(strsql, "m_upload")
            If DT_m_upload.Rows.Count < 1 Then
                MsgBox("ไม่พบข้อมูล", MsgBoxStyle.Exclamation)
                Exit Sub
            End If


            For Each DR_User In DT_m_upload.Select("FILENAME = 'PERSON'")
                LVPPScore.Items(0).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LVPPScore.Items(0).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LVPPScore.Items(0).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'EPI'")
                LVPPScore.Items(1).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LVPPScore.Items(1).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LVPPScore.Items(1).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'ANC'")
                LVPPScore.Items(2).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LVPPScore.Items(2).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LVPPScore.Items(2).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'FP'")
                LVPPScore.Items(3).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LVPPScore.Items(3).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                LVPPScore.Items(3).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'MCH'")
                LVPPScore.Items(4).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LVPPScore.Items(4).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                If DR_User.Item("AMOUNT") <> 0 Then
                    Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                    LVPPScore.Items(4).SubItems.Item(3).Text = MyPassPercent.ToString("c")
                Else
                    LVPPScore.Items(4).SubItems.Item(3).Text = 0
                End If
                Exit For
            Next

            For Each DR_User In DT_m_upload.Select("FILENAME = 'PP'")
                LVPPScore.Items(5).SubItems.Item(1).Text = Val(DR_User.Item("AMOUNT")).ToString("0,0")
                LVPPScore.Items(5).SubItems.Item(2).Text = Val(DR_User.Item("ERROR")).ToString("0,0")
                If DR_User.Item("AMOUNT") <> 0 Then
                    Dim MyPassPercent As Double = (Val(DR_User.Item("AMOUNT")) - Val(DR_User.Item("ERROR"))) / Val(DR_User.Item("AMOUNT")) * 100
                    LVPPScore.Items(5).SubItems.Item(3).Text = IIf(MyPassPercent.ToString("c") < 0, 0, MyPassPercent.ToString("c"))
                Else
                    LVPPScore.Items(5).SubItems.Item(3).Text = 0
                End If
                Exit For
            Next
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
#End Region
    Private Sub frmPoint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try


            strsql = "select ROWID,FILENAME from m_files_upload where TYPE_DESC = 'OP Package'  or  TYPE_DESC = '18 แฟ้ม' order by Date_SEND DESC"
            With Me.CboImportOPFile

                DT_m_files_upload = mysql.GetMYSQLDataTable(strsql, "m_files_upload")
                If DT_m_files_upload.Rows.Count = 0 Then
                    
                    MsgBox("คุณต้องนำข้อมูลเข้าโปรแกรมตรวจสอบ NHSO OPPP 2554 ก่อน", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If
                .DataSource = DT_m_files_upload
                .DisplayMember = "FILENAME"
                .ValueMember = "ROWID"
                Me.CboImportOPFile.SelectionStart = DT_m_files_upload.Rows(0).Item("ROWID").ToString

            End With
        


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Try
            strsql = "select ROWID,FILENAME from m_files_upload where TYPE_DESC = 'PP Package'  or  TYPE_DESC = '18 แฟ้ม' order by Date_SEND DESC"
            With Me.CboImportPPFile

                DT_m_files_upload = mysql.GetMYSQLDataTable(strsql, "m_files_upload")
                If DT_m_files_upload.Rows.Count = 0 Then

                    MsgBox("คุณต้องนำข้อมูลเข้าโปรแกรมตรวจสอบ NHSO OPPP 2554 ก่อน", MsgBoxStyle.Exclamation)
                    Exit Sub
                End If
                .DataSource = DT_m_files_upload
                .DisplayMember = "FILENAME"
                .ValueMember = "ROWID"
                Me.CboImportOPFile.SelectionStart = DT_m_files_upload.Rows(0).Item("ROWID").ToString

            End With





        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        View_Point()
        On_Load = False
    End Sub




    Private Sub OKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OKButton.Click
        Me.Dispose()
    End Sub

  
    Private Sub CboImportOPFile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboImportOPFile.SelectedIndexChanged
        If On_Load = True Then Exit Sub
        View_Point()

    End Sub

    Private Sub CboImportPPFile_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CboImportPPFile.SelectedIndexChanged
        If On_Load = True Then Exit Sub
        View_Point()
    End Sub
End Class